package baidu.com.matedemo.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.baidu.duer.libcore.view.ProgressDialog;

/**
 * Created by niufei01 on 2017/12/29.
 */

public abstract class BaseFragment extends Fragment {

    Activity mActivity;
    ProgressDialog progressDialog;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.mActivity = activity;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = onCreateContentViewCompat(inflater, container, savedInstanceState);
        onContentViewCreated(view);
        return view;
    }

    public abstract View onCreateContentViewCompat(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState);

    public abstract void onContentViewCreated(final View view);

    public Activity getMActivity() {
        return mActivity;
    }


    public void showProgressBar() {

        progressDialog = new ProgressDialog(getMActivity());
        progressDialog.show();
    }

    public void dismissProgressBar() {
        try {
            if (progressDialog != null) {
                progressDialog.dismiss();
            }
        } catch (Exception e) {
            // do nothing
        }

    }

}
